#ifndef ABSTRACTSECURITYCONTEXT_H
#define ABSTRACTSECURITYCONTEXT_H

#include <memory>
using namespace std;

#include <plugin/plugin_global.h>

#include <QString>

namespace antu
{
namespace plugin
{
/**
 * @brief An AbstractSecurityContext is the base class that holds security information for a plugin/module.
 *
 * Implementations should sub-class from AbstractSecurityContext and provide their own license handling.
 * Each security context represents license for a particular plugin/module.
 *
 * //TODO
 */
class AbstractSecurityContext
{
public:
    /**
     * @brief Constructor
     * @param moduleCode Code for the plugin or any module the developer wishes to provide license control.
     * @param p License string for the particular module.
     * @param length Length of the license string. If unspecified, SecurityContext will try to
     *               calculate the length using strlen.
     */
    AbstractSecurityContext(const QString& moduleCode, const char* p, size_t length);

    /**
     * @brief Destructor.
     */
    virtual ~AbstractSecurityContext();

    /**
     * @TODO
     * @brief Checks whether user has the right to use the plugin/module.
     * @return True if user has the right, false otherwise.
     */
    virtual bool isAllowed() const = 0;

    /**
     * @TODO
     * @brief Checks whether user has the right to use a particular unit/service in the plugin/module.
     * @param unit Name of the unit.
     * @return True if user has the right, false otherwise.
     */
    virtual bool isAllowed(const QString& unit) const = 0;

protected:
    char* m_pSecurityToken;
    QString m_sModuleCode;
    int m_iLength;
};

typedef shared_ptr<AbstractSecurityContext> AbstractSecurityContextSharedPtr;

class PLUGINSHARED_EXPORT NullSecurityContext : public AbstractSecurityContext
{
public:
    NullSecurityContext(const QString& moduleName)
        : AbstractSecurityContext(moduleName, nullptr, 0)
    {

    }

    virtual bool isAllowed() const { return true; }
    virtual bool isAllowed(const QString& unit) const;
};
}
}


#endif // ABSTRACTSECURITYCONTEXT_H
